<?php

namespace app\admin\model;


class AdminRole extends Model
{
    CONST PK = 'role_id';
    protected $pk = "role_id";
    protected $name = "admin_role";
    /**
     * $id
     */
    static function getRow($id)
    {
        return static::where(static::PK,'=',$id)->find();
    }

    
    function saveInfo($data)
    {
        $data['rules'] = implode(",",$data['rules']);
        return $this->save($data);
    }

    static function createRow($data)
    {
        $data['rules'] = implode(",",$data['rules']);
        return static::create($data);
    }

    function users()
    {
        return $this->hasMany(AdminUser::class,'role_id');
    }

    function getRulesAttr($value)
    {
        return array_filter(explode(",",$value));
    }

}